package info.androidhive.pratap;

import info.androidhive.volleyexamples.R;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;

public class ProgressActivity extends Activity {

	ListView listView;
	LinearLayout layout;
	List<String> stringValues;
	ArrayAdapter<String> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.progress_activity);
		listView = (ListView) findViewById(R.id.listView);
		layout = (LinearLayout) findViewById(R.id.progressbar_view);

		stringValues = new ArrayList<String>();
		
		adapter = new ArrayAdapter<String>(ProgressActivity.this,
				android.R.layout.simple_list_item_1, stringValues);

		listView.setAdapter(adapter);

		new Task().execute();

	}

	class Task extends AsyncTask<String, Integer, Boolean> {
		@Override
		protected void onPreExecute() {
			layout.setVisibility(View.VISIBLE);
			listView.setVisibility(View.GONE);
			super.onPreExecute();
		}

		@Override
		protected Boolean doInBackground(String... params) {
			stringValues.add("String 1");
			stringValues.add("String 2");
			stringValues.add("String 3");
			stringValues.add("String 4");
			stringValues.add("String 5");

			try {
				Thread.sleep(3000);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}

		@Override
		protected void onPostExecute(Boolean result) {
			layout.setVisibility(View.GONE);
			listView.setVisibility(View.VISIBLE);
			adapter.notifyDataSetChanged();
			super.onPostExecute(result);

			
		}
	}

}
